The TextField Component > FTextField.setValidationFunction()

 

FTextField.setValidationFunction()

Availability

Flash Player 6.

Usage

myTextField_txf.setValidationFunction (fnc [, scope])

Parameters

fnc A String specifying the name of the function that will be called to validate the data in the field. This function is automatically called when the isValid() method is called on the component.

scope An Object whose scope the validation function will be run within. This parameter if optional.

Returns

Nothing

Description

This method specifies the function that will be called when isValid is called on the component. This makes it easy to validate user input.

The function used for the validation function will be passed two parameters:

text

The text within the text field.

componentRef

A reference to the component that isValid is being called on.

The validation function below validates that the user has entered a number into the text field.

function numValidation(text, componentRef)
{
	return !isNan(char);
}

 

Example

The text_validation.fla and text_isValid.fla example files contain an examples of using this method.

The following example defines a validation function that returns true if the user input is a number, and false if it is not.

function validate(text)
{
    return !isNan(char);
}


myTextField_txf.setValidationFunction("validate");

if(myTextField_txf.isValid())
{
	trace("Input is a Valid Number");
}
else
{
	trace("Input is not a Valid Number");
}

 

See also

FTextField.getValidationFunction()

FTextField.isValid()